package cnam.smb215.findfriends;

import java.util.ArrayList;

import android.app.AlertDialog;
import android.content.Context;
import android.text.format.DateFormat;

import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;

public class PersonItemizedOverlay extends ItemizedOverlay<OverlayItem> {
	private Context mContext;
	private Person mPerson;
	private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();

	public PersonItemizedOverlay(Person person, Context context) {
		super(boundCenterBottom(person.getID()==Globals.MY_ID? Globals.DEFAULT_ICON:Globals.DEFAULT_ICON_USERS));
		mContext = context;
		mPerson = person;
	}

	@Override
	protected boolean onTap(int index) {
		//OverlayItem item = mOverlays.get(index);
		AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
		//dialog.setTitle(item.getTitle());
		dialog.setTitle(mPerson.getName());
		//DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
		dialog.setMessage("Last Seen at " + DateFormat.format("yyyy-MM-dd hh:mm:ss", mPerson.getLastSeen()));
		//dialog.setMessage(item.getSnippet());
		dialog.show();
		return true;
	}

	@Override
	protected OverlayItem createItem(int index) {
		return mOverlays.get(index);
	}

	@Override
	public int size() {
		return mOverlays.size();
	}

	public void addOverlay(OverlayItem overlay) {
		mOverlays.clear();
		mOverlays.add(overlay);
		mPerson.updateLocation(overlay.getPoint().getLatitudeE6(), overlay.getPoint().getLongitudeE6());
		populate();
	}
}
